<?php
    class tag {
        /**
         * 读取非顶级栏目的文章
         */
        function _arclist($attr,$content){

            $row = isset($attr['row'])?$attr['row'] : 5;
            $cid = isset($attr['cid'])?$attr['cid'] : '$_GET[cid]';
            // p($cid);die;
            $str='';
            $str.='<?php $db = M("arc");'."\n";
            // $str.='$sql=select * from ec_category where pid='.$cid.' as c join ec_arc as a on where a.cid=c.cid';
            $str.='$rows = $db->where("cid='.$cid.'")->order("aid desc")->limit('.$row.')->all();'."\n";
            $str.='foreach($rows as $field):?>'."\n";
            $str.=$content;
            $str.='<?php endforeach;?>'."\n";
            return $str;

        }
        /**
         * 读取列表页
         */
        function _catlist($attr,$content){

            $str='';
            $str.='<?php $db = M("category");'."\n";
            $str.='$cid = $_GET["cid"];'."\n";
            $str.='$rows = $db->where("pid=$cid")->all();'."\n";
            $str.='foreach($rows as $field):?>'."\n";
            $str.=$content;
            $str.='<?php endforeach;?>'."\n";
            return $str;

        }
        /**
         * 读取联系我们
         */
        function _lianxi($attr,$content){

            $str='';
            $str.='<?php $db = M("config");'."\n";
            $str.='$rows = $db->where("cid>5")->all();'."\n";
            $str.='foreach ($rows as $field):?>'."\n";
            $str.=$content;
            $str.='<?php endforeach;?>'."\n";
            return $str;

        }

        function _parentarclist(){

        }
        /**
         * 读取顶级栏目图片列表
         */
        function _tparclist($attr,$content){
            $row = isset($attr['row'])?$attr['row'] : 5;
            $cid = isset($attr['cid'])?$attr['cid'] : '$_GET[cid]';

            $str='';
            $str.='<?php'."\n";
            $str.='$sql="select * from ".C("DB_PREFIX")."category as c join ec_arc as a where c.pid='.$cid.' and c.cid=a.cid";'."\n";
            $str.='$rows = M()->query($sql);'."\n";
            $str.='foreach($rows as $field):?>'."\n";
            $str.=$content;
            $str.='<?php endforeach;?>'."\n";
            return $str;
         }
         /**
         * 读取顶级栏目文章列表
         */
         function _parclist($attr,$content){
            $row = isset($attr['row'])?$attr['row'] : 5;
            $cid = isset($attr['cid'])?$attr['cid'] : '$_GET[cid]';

            $str='';
            $str.='<?php'."\n";
            $str.='$sql="select * from ".C("DB_PREFIX")."category as c join ec_arc as a where c.pid='.$cid.' and c.cid=a.cid";'."\n";
            $str.='$rows = M()->query($sql);'."\n";
            $str.='foreach($rows as $field):?>'."\n";
            $str.=$content;
            $str.='<?php endforeach;?>'."\n";
            return $str;
         }

         function _arc($attr,$content){

            $aid = isset($attr['aid'])?$attr['aid'] : '$_GET[aid]';
            // p($aid);die;
            $str='';
            $str.='<?php'."\n";
            $str.='$db=M("arc");'."\n";
            $str.='$rows=$db->where("aid='.$aid.'")->all();'."\n";
            $str.='foreach($rows as $field):?>'."\n";
            $str.=$content;
            $str.='<?php endforeach;?>'."\n";
            return $str;

         }

         function _commentlist($attr,$content){
            $row = isset($attr['row'])?$attr['row'] : 10;
            $aid = isset($attr['aid'])?$attr['aid'] : '$_GET[aid]'; 
            $str='';
            $str.='<?php $db = M("comment");'."\n";
            $str.='$rows = $db->where(array("aid"=>'.$aid.',"over"=>1))->order("cmid desc")->limit('.$row.')->all();'."\n";
            $str.='foreach($rows as $field):?>'."\n";
            $str.=$content;
            $str.='<?php endforeach;?>'."\n";
            return $str;

         }
    }
?>
